package com.lfk.justweengine.Utils.tools;

import com.lfk.justweengine.Info.UIdefaultData;
import ohos.agp.components.AttrHelper;
import ohos.app.Context;

/**
 * Created by liufengkai on 15/11/8.
 */
public class DisplayUtils {
    /**
     * px to dip 尺寸不变
     *
     * @param context
     * @param pxValue
     * @return
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResourceManager().getDeviceCapability().screenDensity;
        return (int) (pxValue / scale + 0.5f);
    }


    /**
     * dip to px 尺寸不变
     *
     * @param context
     * @param dipValue
     * @return
     */
    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResourceManager().getDeviceCapability().screenDensity;
        return (int) (dipValue * scale + 0.5f);
    }

    public static float dip2px(float dipValue) {
        return (dipValue * UIdefaultData.scale + 0.5f);
    }

    /**
     * vp to px
     *
     * @param context
     * @param vp
     * @return
     */
    public static int vp2px(Context context, int vp) {
        return AttrHelper.vp2px((float) vp, context);
    }

    /**
     * fp to px
     *
     * @param context
     * @param fpValue
     * @return
     */
    public static int fp2px(Context context, float fpValue) {
        return AttrHelper.vp2px(fpValue, context);
    }
}
